using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;

namespace lt_pmbc_001.DAL
{
	#region using
	using System.Data;
	using lt_pmbc_001.DTO;
	using lt_pmbc_001.Helpers;
    using System.Data.OleDb;
	#endregion

	/// <summary>
	/// Data access object, which get data of LichSuBaoChay table from database
	/// </summary>
    public class LichSuBaoChayDAL : AbstractDAL
	{
		public LichSuBaoChayDAL(string strPath): base(strPath)
		{
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_LichSuBaoChay_SelectAll";
				base.FillDataSet(ref ds, "LichSuBaoChay");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

        public DataSet RetrieveMaxID()
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_LichSuBaoChay_RetrieveMaxID";
                base.FillDataSet(ref ds, "RetrieveMaxID");
                return ds;
            }
            catch (System.Exception ex)
            {
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
            }
            finally
            {
                base.CleanUpObject();
            }
            return null;
        }

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_LichSuBaoChay_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				base.FillDataSet(ref ds, "LichSuBaoChay");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public bool Insert(LichSuBaoChayDTO obj)
		{
			try
			{
				base.sql = "usp_LichSuBaoChay_Insert";
				base.InitializeCommand();
				base.AddParameter("@IDChiTietDiaDiem", OleDbType.VarChar, 1000, obj.IDChiTietDiaDiem);
				base.AddParameter("@NgayBaoChay", OleDbType.Date, 1000, obj.NgayBaoChay);
                base.AddParameter("@TinhTrang", OleDbType.VarChar, 1000, obj.TinhTrang);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Update(LichSuBaoChayDTO obj)
		{
			try
			{
				base.sql = "usp_LichSuBaoChay_Update";
				base.InitializeCommand();
                base.AddParameter("@TinhTrang", OleDbType.VarChar, 1000, obj.TinhTrang);
                base.AddParameter("@ID", OleDbType.Integer, 1000, obj.ID);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Delete()
		{
			try
			{
				base.sql = "usp_LichSuBaoChay_Delete";
				base.InitializeCommand();
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public DataSet SelectByIDChiTietDiaDiem(int idchitietdiadiem)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_LichSuBaoChay_SelectByIDChiTietDiaDiem";
				base.InitializeCommand();
				base.AddParameter("@IDChiTietDiaDiem", OleDbType.VarChar, 1000, idchitietdiadiem);
				base.FillDataSet(ref ds, "LichSuBaoChay");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

	}
}